/**
 * Created by dukes on 2015/10/28.
 */
//module game{
    class DecDetailItemRender extends eui.ItemRenderer{
        private frameItem:FrameItem;
        public static NUM = 0;
        public constructor(){
            super();
            this.skinName = "pet.DecDetailRenderSkin";
            this.name = "decdetailitem"+DecDetailItemRender.NUM;
            this.frameItem = new FrameItem();
            this.frameItem.callFun = this.update;
            this.frameItem.callObj = this;
            DecDetailItemRender.NUM++;
            this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAdded, this);
            this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoved, this);
        }
        public update(delta:number){
            if( this.data instanceof Array){
                this.group_timeleft.text = "y";
            }else{
                if( this.data.isPernant){
                    this.group_timeleft.text = "y";
                }else{
                    var timegap = this.data.expireTime - Model.SYSTIME;
                    if( timegap > 0){
                        var timestr = GetTimeStr(timegap,2,true);
                        this.group_timeleft.text = timestr;
                    }else{
                        //todo how
                    }
                }
            }

        }
        private onAdded(evt:egret.TouchEvent){
            FrameMgr.getInstance().addControll(this.frameItem);
        }

        private onRemoved(evt:egret.TouchEvent){
            FrameMgr.getInstance().delController(this.name);
        }
        private lab_name:eui.Label;
        private img_icon:eui.Image;
        private img_attr:eui.Image;
        private img_plus:eui.Image;
        private group_attr_cnt:eui.BitmapLabel;
        private group_timeleft:eui.BitmapLabel;
        public partAdded(name:string, instance:any){
            super.partAdded(name, instance);
            if( name =="lab_name" ){
                this.lab_name = instance;
            }else if( name =="img_icon" ){
                this.img_icon = instance;
            }else if( name =="img_attr" ){
                this.img_attr = instance;
            }else if( name =="img_plus" ){
                this.img_plus = instance;
            }else if( name =="group_attr_cnt" ){
                this.group_attr_cnt = instance;
            }else if( name =="group_timeleft" ){
                this.group_timeleft = instance;
            }
        }
        private curShowNum;
        public dataChanged(){
            super.dataChanged();
            if( this.data instanceof Array){//Guild Medal
                var type = this.data[0];
                this.lab_name.text = "族徽";
                // this.img_icon.source = GameConst.Res_Root+"resource/assets/medals/"+GuildMgr.getInstance().guildLogo.logoId+".png";
                this.group_attr_cnt.text = this.data[1]+"";
                if( type == 0){//attack
                    this.img_attr.source = "preload_json.img_attack";
                }else if( type == 1){//defense
                    this.img_attr.source = "preload_json.img_defense";
                }
                this.group_timeleft.text = "y";
                FrameMgr.getInstance().delController(this.name);
            }else{//װ��
                var decData = Model.GetDecDateById(this.data.goodsId);
                this.lab_name.text = decData.name;
                if( decData.classify != 4)
                    this.img_icon.source = GameConst.Res_Root+"resource/assets/decorates/"+decData.id+".png";
                else
                    this.img_icon.source = GameConst.Res_Root+"resource/assets/decorates/"+decData.id+"-1.jpg";

                var num;
                if( this.data.attack ){
                    this.img_attr.source = "preload_json.img_attack";
                    num = this.data.attack;
                }else if( this.data.defense){
                    this.img_attr.source = "preload_json.img_defense";
                    num = this.data.defense;
                }else if( this.data.blood){
                    this.img_attr.source = "preload_json.img_blood";
                    num = this.data.blood;
                }else if( this.data.speed){
                    this.img_attr.source = "preload_json.img_speed";
                    num = this.data.speed;
                }else if( this.data.difficulty){
                    this.img_attr.source = "preload_json.img_hardness";
                    num = this.data.difficulty;
                }else if( decData.autoHairPer != 0){
                    this.img_attr.source = "preload_json.img_produce";
                    num = decData.autoHairPer+"%";
                }
                if( this.curShowNum != num){
                    this.group_attr_cnt.text = num+"";
                    this.curShowNum = num;
                }
            }
        }
    }
//}